// Predefined mission scenarios for the drone

export const MISSION_SCENARIOS = {
  // Basic patrol mission
  PERIMETER_PATROL: {
    id: 'perimeter_patrol',
    name: 'Perimeter Patrol',
    description: 'Patrol around a rectangular perimeter',
    duration: 60, // seconds
    waypoints: [
      { position: [0, 3, 0], action: { type: 'hover', duration: 2 } },
      { position: [5, 3, 0], action: { type: 'scan', duration: 3 } },
      { position: [5, 3, 5], action: { type: 'scan', duration: 3 } },
      { position: [-5, 3, 5], action: { type: 'scan', duration: 3 } },
      { position: [-5, 3, -5], action: { type: 'scan', duration: 3 } },
      { position: [5, 3, -5], action: { type: 'scan', duration: 3 } },
      { position: [0, 3, 0], action: { type: 'hover', duration: 2 } }
    ],
    type: 'patrol'
  },

  // Search and rescue simulation
  SEARCH_RESCUE: {
    id: 'search_rescue',
    name: 'Search & Rescue',
    description: 'Search pattern for missing person simulation',
    duration: 90,
    waypoints: [
      { position: [0, 4, 0], action: { type: 'hover', duration: 2 } },
      { position: [3, 4, 3], action: { type: 'scan', duration: 5 } },
      { position: [0, 4, 6], action: { type: 'scan', duration: 5 } },
      { position: [-3, 4, 3], action: { type: 'scan', duration: 5 } },
      { position: [-6, 4, 0], action: { type: 'scan', duration: 5 } },
      { position: [-3, 4, -3], action: { type: 'scan', duration: 5 } },
      { position: [0, 4, -6], action: { type: 'scan', duration: 5 } },
      { position: [3, 4, -3], action: { type: 'scan', duration: 5 } },
      { position: [6, 4, 0], action: { type: 'scan', duration: 5 } },
      { position: [0, 4, 0], action: { type: 'hover', duration: 3 } }
    ],
    type: 'search'
  },

  // Delivery simulation
  PACKAGE_DELIVERY: {
    id: 'package_delivery',
    name: 'Package Delivery',
    description: 'Simulate package delivery to multiple locations',
    duration: 75,
    waypoints: [
      { position: [0, 2, 0], action: { type: 'hover', duration: 2 } },
      { position: [4, 3, 2], action: { type: 'delivery', duration: 5 } },
      { position: [2, 3, 6], action: { type: 'delivery', duration: 5 } },
      { position: [-3, 3, 4], action: { type: 'delivery', duration: 5 } },
      { position: [-5, 3, -2], action: { type: 'delivery', duration: 5 } },
      { position: [0, 2, 0], action: { type: 'land', duration: 3 } }
    ],
    type: 'delivery'
  },

  // Surveillance mission
  AREA_SURVEILLANCE: {
    id: 'area_surveillance',
    name: 'Area Surveillance',
    description: 'Monitor specific area with detailed scanning',
    duration: 120,
    waypoints: [
      { position: [0, 5, 0], action: { type: 'hover', duration: 3 } },
      { position: [2, 5, 2], action: { type: 'surveillance', duration: 8 } },
      { position: [-2, 5, 2], action: { type: 'surveillance', duration: 8 } },
      { position: [-2, 5, -2], action: { type: 'surveillance', duration: 8 } },
      { position: [2, 5, -2], action: { type: 'surveillance', duration: 8 } },
      { position: [0, 6, 0], action: { type: 'overview', duration: 10 } },
      { position: [0, 3, 0], action: { type: 'hover', duration: 3 } }
    ],
    type: 'surveillance'
  },

  // Inspection mission
  INFRASTRUCTURE_INSPECTION: {
    id: 'infrastructure_inspection',
    name: 'Infrastructure Inspection',
    description: 'Inspect infrastructure at various heights and angles',
    duration: 100,
    waypoints: [
      { position: [0, 1, 0], action: { type: 'hover', duration: 2 } },
      { position: [3, 2, 0], action: { type: 'inspect', duration: 6 } },
      { position: [3, 4, 0], action: { type: 'inspect', duration: 6 } },
      { position: [3, 6, 0], action: { type: 'inspect', duration: 6 } },
      { position: [0, 6, 3], action: { type: 'inspect', duration: 6 } },
      { position: [-3, 6, 0], action: { type: 'inspect', duration: 6 } },
      { position: [-3, 4, 0], action: { type: 'inspect', duration: 6 } },
      { position: [-3, 2, 0], action: { type: 'inspect', duration: 6 } },
      { position: [0, 2, 0], action: { type: 'hover', duration: 3 } }
    ],
    type: 'inspection'
  },

  // Emergency response
  EMERGENCY_RESPONSE: {
    id: 'emergency_response',
    name: 'Emergency Response',
    description: 'Rapid response to emergency situation',
    duration: 45,
    waypoints: [
      { position: [0, 2, 0], action: { type: 'takeoff', duration: 1 } },
      { position: [6, 4, 6], action: { type: 'assess', duration: 5 } },
      { position: [6, 6, 6], action: { type: 'overview', duration: 3 } },
      { position: [6, 3, 6], action: { type: 'deploy_aid', duration: 8 } },
      { position: [0, 4, 0], action: { type: 'return', duration: 2 } },
      { position: [0, 2, 0], action: { type: 'land', duration: 2 } }
    ],
    type: 'emergency'
  },

  // Mapping mission
  AERIAL_MAPPING: {
    id: 'aerial_mapping',
    name: 'Aerial Mapping',
    description: 'Create aerial map of the area with systematic coverage',
    duration: 150,
    waypoints: [
      { position: [0, 5, 0], action: { type: 'hover', duration: 2 } },
      // Grid pattern for mapping
      { position: [-4, 5, -4], action: { type: 'photo', duration: 3 } },
      { position: [-2, 5, -4], action: { type: 'photo', duration: 3 } },
      { position: [0, 5, -4], action: { type: 'photo', duration: 3 } },
      { position: [2, 5, -4], action: { type: 'photo', duration: 3 } },
      { position: [4, 5, -4], action: { type: 'photo', duration: 3 } },
      { position: [4, 5, -2], action: { type: 'photo', duration: 3 } },
      { position: [2, 5, -2], action: { type: 'photo', duration: 3 } },
      { position: [0, 5, -2], action: { type: 'photo', duration: 3 } },
      { position: [-2, 5, -2], action: { type: 'photo', duration: 3 } },
      { position: [-4, 5, -2], action: { type: 'photo', duration: 3 } },
      { position: [-4, 5, 0], action: { type: 'photo', duration: 3 } },
      { position: [-2, 5, 0], action: { type: 'photo', duration: 3 } },
      { position: [0, 5, 0], action: { type: 'photo', duration: 3 } },
      { position: [2, 5, 0], action: { type: 'photo', duration: 3 } },
      { position: [4, 5, 0], action: { type: 'photo', duration: 3 } },
      { position: [4, 5, 2], action: { type: 'photo', duration: 3 } },
      { position: [2, 5, 2], action: { type: 'photo', duration: 3 } },
      { position: [0, 5, 2], action: { type: 'photo', duration: 3 } },
      { position: [-2, 5, 2], action: { type: 'photo', duration: 3 } },
      { position: [-4, 5, 2], action: { type: 'photo', duration: 3 } },
      { position: [-4, 5, 4], action: { type: 'photo', duration: 3 } },
      { position: [-2, 5, 4], action: { type: 'photo', duration: 3 } },
      { position: [0, 5, 4], action: { type: 'photo', duration: 3 } },
      { position: [2, 5, 4], action: { type: 'photo', duration: 3 } },
      { position: [4, 5, 4], action: { type: 'photo', duration: 3 } },
      { position: [0, 5, 0], action: { type: 'hover', duration: 3 } }
    ],
    type: 'mapping'
  },

  // Training mission
  FLIGHT_TRAINING: {
    id: 'flight_training',
    name: 'Flight Training',
    description: 'Basic flight maneuvers for training purposes',
    duration: 60,
    waypoints: [
      { position: [0, 2, 0], action: { type: 'hover', duration: 3 } },
      { position: [2, 2, 0], action: { type: 'hover', duration: 2 } },
      { position: [2, 4, 0], action: { type: 'hover', duration: 2 } },
      { position: [0, 4, 2], action: { type: 'hover', duration: 2 } },
      { position: [-2, 4, 2], action: { type: 'hover', duration: 2 } },
      { position: [-2, 2, 0], action: { type: 'hover', duration: 2 } },
      { position: [0, 2, -2], action: { type: 'hover', duration: 2 } },
      { position: [2, 2, -2], action: { type: 'hover', duration: 2 } },
      { position: [0, 3, 0], action: { type: 'circle', duration: 10 } },
      { position: [0, 2, 0], action: { type: 'land', duration: 3 } }
    ],
    type: 'training'
  }
};

// Get mission by ID
export function getMission(missionId) {
  return MISSION_SCENARIOS[missionId] || null;
}

// Get all missions of a specific type
export function getMissionsByType(type) {
  return Object.values(MISSION_SCENARIOS).filter(mission => mission.type === type);
}

// Get all available missions
export function getAllMissions() {
  return Object.values(MISSION_SCENARIOS);
}

// Get mission types
export function getMissionTypes() {
  const types = new Set();
  Object.values(MISSION_SCENARIOS).forEach(mission => types.add(mission.type));
  return Array.from(types);
}
